<?php
/**
 * FeedbackController.class.php
 * 意见反馈控制器
 *
 * @author   <王中艺>
 * @date  2017-02-18
 */
namespace Admin\Controller;

class FeedbackController extends BaseController {
	/**
	 * 获取意见反馈列表
	 * @param   $status 状态
	 * @param   $p 页码数
	 */
	function getList(){
		$status 	= $this->iInfo['status'];
		$page 	= $this->iInfo['p'] ? $this->iInfo['p'] : 1;
		$pageHtml 	= 0;
		$list 	= D('Feedback')->getList($status, $page, $pageHtml);
		if($list === false){
			$this->outOInfo(D('Feedback')->errMsg, 0);
		}
		$this->outOInfo(array('list' => $list, 'page_html' => $pageHtml));
	}

	/**
	 * 意见详情获取
	 * @param   $feed_id 意见ID
	 * @return  $info
	 */
	function getDetail(){
		$this->unEmptyParam(array('feed_id'));
		$feedId 	= $this->iInfo['feed_id'];

		$info 	= D('Feedback')->getDetail($feedId);
		if($info === false)
			$this->outOInfo(D('Feedback')->errMsg, 0);
		$this->outOInfo(array('info' => $info));
	}

	/**
	 * 处理意见
	 * @param   $feed_id 意见ID
	 * @param   $reward_score [description]
	 */
	function dealItem(){
		$this->unEmptyParam(array('feed_id', 'reward_score'));
		$feedId 	= $this->iInfo['feed_id'];
		$rewardScore 	= $this->iInfo['reward_score'];

		//检测及分数是否合理
		if(!in_array($rewardScore, array(0, 50, 200, 500))){
			$this->outOInfo('奖励积分数非法!', 0);
		}

		$Model 	= new \Think\Model();
		$Model->startTrans();
		//处理意见
		$result 	= D('Feedback')->dealItem($feedId, $rewardScore, UID);
		if($result === false){
			$Model->rollback();
			$this->outOInfo(D('Feedback')->errMsg, 0);
		}

		//发送积分
		if($rewardScore > 0){
			$feedInfo 	= D('Feedback')->getDetail($feedId);
			$result 	= D('Score')->addScore($feedInfo['user_id'], 7, $feedId, $rewardScore, '意见反馈', true);
			if($result === false){
				$Model->rollback();
				$this->outOInfo(D('Score')->errMsg, 0);
			}
		}
		$Model->commit();	

		$this->outOInfo('Oh yes!');
	}

	function debug(){
		$cacheKey 	= sprintf('feedlist_s%d_p%d', $this->iInfo['status'], $this->iInfo['p']);
		$this->outOInfo($cacheKey);
	}
}